{% extends "base.html" %}

{% block content %}
<!-- 跨区域项目概览 -->
<div class="section">
    <div class="section-title">🌐 跨区域项目概览</div>
    <div class="section-content">
        {% if data.cross_region_overview %}
        <div class="stats-cards">
            <div class="stat-card">
                <div class="stat-value">{{ data.cross_region_overview.project_name }}</div>
                <div class="stat-label">项目名称</div>
            </div>
            <div class="stat-card">
                <div class="stat-value">{{ data.cross_region_overview.region_count | format_number }}</div>
                <div class="stat-label">覆盖区域</div>
            </div>
            <div class="stat-card">
                <div class="stat-value">{{ data.cross_region_overview.total_devices | format_number }}</div>
                <div class="stat-label">设备总数</div>
            </div>
            <div class="stat-card">
                <div class="stat-value {{ 'highlight-good' if data.cross_region_overview.coordination_index > 0.8 else 'highlight-bad' }}">
                    {{ (data.cross_region_overview.coordination_index * 100) | round(1) }}%
                </div>
                <div class="stat-label">协调指数</div>
            </div>
        </div>
        {% endif %}
    </div>
</div>

<!-- 各区域项目执行情况 -->
<div class="section">
    <div class="section-title">📊 各区域项目执行情况</div>
    <div class="section-content">
        {% if data.region_execution %}
        <table class="data-table">
            <thead>
                <tr>
                    <th>区域名称</th>
                    <th>设备数量</th>
                    <th>工作天数</th>
                    <th>总工作时间</th>
                    <th>区域效率</th>
                    <th>进度完成度</th>
                    <th>执行状态</th>
                </tr>
            </thead>
            <tbody>
                {% for region in data.region_execution %}
                <tr>
                    <td>{{ region.region_name }}</td>
                    <td>{{ region.device_count | format_number }}</td>
                    <td>{{ region.work_days | format_number }}</td>
                    <td class="highlight-number">{{ region.total_work_time | format_duration }}</td>
                    <td class="{{ 'highlight-good' if region.efficiency > 0.8 else 'highlight-bad' }}">
                        {{ (region.efficiency * 100) | round(1) }}%
                    </td>
                    <td class="{{ 'highlight-good' if region.progress > 0.9 else 'highlight-bad' }}">
                        {{ (region.progress * 100) | round(1) }}%
                    </td>
                    <td class="{{ 'highlight-good' if region.status == '正常' else 'highlight-bad' }}">
                        {{ region.status }}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
        <div class="no-data">暂无区域执行数据</div>
        {% endif %}
    </div>
</div>

<!-- 区域间协调分析 -->
<div class="section">
    <div class="section-title">🤝 区域间协调分析</div>
    <div class="section-content">
        {% if data.coordination_analysis %}
        <table class="data-table">
            <thead>
                <tr>
                    <th>协调项目</th>
                    <th>涉及区域</th>
                    <th>同步程度</th>
                    <th>资源共享率</th>
                    <th>通信效率</th>
                    <th>协调评分</th>
                </tr>
            </thead>
            <tbody>
                {% for coord in data.coordination_analysis %}
                <tr>
                    <td>{{ coord.coordination_item }}</td>
                    <td>{{ coord.involved_regions }}</td>
                    <td class="{{ 'highlight-good' if coord.sync_level > 0.8 else 'highlight-bad' }}">
                        {{ (coord.sync_level * 100) | round(1) }}%
                    </td>
                    <td class="{{ 'highlight-good' if coord.resource_sharing > 0.7 else 'highlight-bad' }}">
                        {{ (coord.resource_sharing * 100) | round(1) }}%
                    </td>
                    <td class="{{ 'highlight-good' if coord.communication_efficiency > 0.8 else 'highlight-bad' }}">
                        {{ (coord.communication_efficiency * 100) | round(1) }}%
                    </td>
                    <td class="highlight-number">{{ coord.coordination_score | round(1) }}分</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
        <div class="no-data">暂无协调分析数据</div>
        {% endif %}
    </div>
</div>

<!-- 设备分布及流动性 -->
<div class="section">
    <div class="section-title">🔄 设备分布及流动性</div>
    <div class="section-content">
        {% if data.device_mobility %}
        <div style="margin-bottom: 20px;">
            <h4 style="color: #1f4e79; margin-bottom: 10px;">设备区域分布</h4>
            <table class="data-table">
                <thead>
                    <tr>
                        <th>区域名称</th>
                        <th>分配设备数</th>
                        <th>实际使用数</th>
                        <th>流动设备数</th>
                        <th>利用率</th>
                        <th>流动频率</th>
                    </tr>
                </thead>
                <tbody>
                    {% for region in data.device_mobility.distribution %}
                    <tr>
                        <td>{{ region.region_name }}</td>
                        <td>{{ region.allocated_devices | format_number }}</td>
                        <td>{{ region.active_devices | format_number }}</td>
                        <td>{{ region.mobile_devices | format_number }}</td>
                        <td class="{{ 'highlight-good' if region.utilization > 0.8 else 'highlight-bad' }}">
                            {{ (region.utilization * 100) | round(1) }}%
                        </td>
                        <td class="highlight-number">{{ region.mobility_frequency | round(2) }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        {% if data.device_mobility.transfer_records %}
        <div>
            <h4 style="color: #1f4e79; margin-bottom: 10px;">近期设备流转记录</h4>
            <table class="data-table">
                <thead>
                    <tr>
                        <th>设备编号</th>
                        <th>源区域</th>
                        <th>目标区域</th>
                        <th>流转时间</th>
                        <th>使用效果</th>
                    </tr>
                </thead>
                <tbody>
                    {% for transfer in data.device_mobility.transfer_records %}
                    <tr>
                        <td>{{ transfer.device_id[-6:] }}</td>
                        <td>{{ transfer.source_region }}</td>
                        <td>{{ transfer.target_region }}</td>
                        <td>{{ transfer.transfer_time | format_date }}</td>
                        <td class="{{ 'highlight-good' if transfer.effectiveness == '良好' else 'highlight-bad' }}">
                            {{ transfer.effectiveness }}
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% endif %}
        {% else %}
        <div class="no-data">暂无设备流动性数据</div>
        {% endif %}
    </div>
</div>

<!-- 项目进度对比 -->
<div class="section">
    <div class="section-title">📈 项目进度对比</div>
    <div class="section-content">
        {% if data.progress_comparison %}
        <table class="data-table">
            <thead>
                <tr>
                    <th>时间节点</th>
                    <th>计划进度</th>
                    <th>实际进度</th>
                    <th>进度偏差</th>
                    <th>风险等级</th>
                    <th>调整建议</th>
                </tr>
            </thead>
            <tbody>
                {% for milestone in data.progress_comparison %}
                <tr>
                    <td>{{ milestone.milestone_name }}</td>
                    <td>{{ (milestone.planned_progress * 100) | round(1) }}%</td>
                    <td class="{{ 'highlight-good' if milestone.actual_progress >= milestone.planned_progress else 'highlight-bad' }}">
                        {{ (milestone.actual_progress * 100) | round(1) }}%
                    </td>
                    <td class="{{ 'highlight-good' if milestone.deviation >= 0 else 'highlight-bad' }}">
                        {{ milestone.deviation | round(1) }}%
                    </td>
                    <td class="{{ 'highlight-good' if milestone.risk_level == '低' else 'highlight-bad' }}">
                        {{ milestone.risk_level }}
                    </td>
                    <td>{{ milestone.suggestion }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
        <div class="no-data">暂无进度对比数据</div>
        {% endif %}
    </div>
</div>

<!-- 跨区域排名 -->
<div class="section">
    <div class="section-title">🏆 跨区域表现排名</div>
    <div class="section-content">
        {% if data.cross_region_rankings %}
        <div style="margin-bottom: 20px;">
            <h4 style="color: #28a745; margin-bottom: 10px;">⬆️ 区域表现排名</h4>
            <table class="data-table">
                <thead>
                    <tr>
                        <th>排名</th>
                        <th>区域名称</th>
                        <th>综合得分</th>
                        <th>执行效率</th>
                        <th>协调能力</th>
                        <th>主要亮点</th>
                    </tr>
                </thead>
                <tbody>
                    {% for region in data.cross_region_rankings.region_ranking %}
                    <tr>
                        <td>{{ loop.index }}</td>
                        <td>{{ region.region_name }}</td>
                        <td class="{{ 'highlight-good' if region.total_score > 80 else 'highlight-bad' }}">
                            {{ region.total_score | round(1) }}分
                        </td>
                        <td class="{{ 'highlight-good' if region.execution_efficiency > 0.8 else 'highlight-bad' }}">
                            {{ (region.execution_efficiency * 100) | round(1) }}%
                        </td>
                        <td class="{{ 'highlight-good' if region.coordination_ability > 0.8 else 'highlight-bad' }}">
                            {{ (region.coordination_ability * 100) | round(1) }}%
                        </td>
                        <td>{{ region.highlight }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% else %}
        <div class="no-data">暂无排名数据</div>
        {% endif %}
    </div>
</div>

<!-- AI分析内容 -->
<div class="section">
    <div class="section-title">🤖 智能分析结论</div>
    <div class="section-content">
        {% if data.content_sections %}
            {% for section_title, content in data.content_sections.items() %}
            <div style="margin-bottom: 20px;">
                <h4 style="color: #1f4e79; margin-bottom: 12px; border-bottom: 1px solid #e0e0e0; padding-bottom: 8px;">{{ section_title }}</h4>
                <div style="text-align: justify; line-height: 1.8; margin-top: 12px;">
                    {{ content | safe }}
                </div>
            </div>
            {% endfor %}
        {% else %}
        <div class="no-data">AI分析内容生成中...</div>
        {% endif %}
    </div>
</div>

<!-- 跨区域协调建议 -->
<div class="section">
    <div class="section-title">💡 跨区域协调建议</div>
    <div class="section-content">
        <div class="success">
            <h4>协调优化建议</h4>
            <ul class="report-list">
                {% if data.cross_region_overview and data.cross_region_overview.coordination_index < 0.8 %}
                <li><strong>提升协调指数：</strong>当前协调指数为 {{ (data.cross_region_overview.coordination_index * 100) | round(1) }}%，建议加强区域间沟通机制。</li>
                {% endif %}
                
                {% if data.region_execution %}
                <li><strong>区域均衡发展：</strong>关注执行效率较低的区域，提供必要的支持和资源倾斜。</li>
                {% endif %}
                
                {% if data.device_mobility %}
                <li><strong>优化设备配置：</strong>根据各区域需求动态调整设备分配，提高整体利用率。</li>
                {% endif %}
                
                {% if data.progress_comparison %}
                <li><strong>进度同步管理：</strong>建立统一的进度监控体系，确保各区域按计划推进。</li>
                {% endif %}
                
                <li><strong>建立协调机制：</strong>设立跨区域协调小组，定期举行协调会议。</li>
                <li><strong>资源共享平台：</strong>建立设备和人员共享平台，提高资源配置效率。</li>
                <li><strong>标准化流程：</strong>制定统一的作业标准和流程，确保各区域执行一致性。</li>
                <li><strong>应急响应机制：</strong>建立跨区域应急响应和支援机制。</li>
            </ul>
        </div>
    </div>
</div>
{% endblock %}